import java.util.Scanner;

public class MC0416最小值之和 {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        // code here
        int n = input.nextInt();
        long[] longs = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            longs[i] = input.nextLong();
        }
        for (int i = 0; i < n; i++) {
            long cur = longs[i];
            for (int j = i; j < n; j++) {
                cur = Math.min(cur, longs[j]);
                ans += cur;
            }
        }
        System.out.println(ans);
        input.close();
    }
}
